

package org.test

import grails.test.mixin.*

import org.junit.*
import org.tests.MainIdealPriceStrategy;

class MainIdealPriceStrategyTests {

	void testWith4Prices() {
	   MainIdealPriceStrategy strategy = new MainIdealPriceStrategy();
	   Set<PriceAssessment> prices = new HashSet<PriceAssessment>();
	   
	   PriceAssessment price1 = new PriceAssessment();
	   price1.setPrice(1);
	   
	   PriceAssessment price2 = new PriceAssessment();
	   price2.setPrice(2);

	   PriceAssessment price3 = new PriceAssessment();
	   price3.setPrice(3);

	   PriceAssessment price4 = new PriceAssessment();
	   price4.setPrice(4);

	   prices.addAll([price1, price2, price3, price4]);
	   
	   BigDecimal idealPrice = (BigDecimal) strategy.getIdealPrice(prices);
	   
	   assert idealPrice == 3;
	}
	
	void testWith5Prices() {
		MainIdealPriceStrategy strategy = new MainIdealPriceStrategy();
		Set<PriceAssessment> prices = new HashSet<PriceAssessment>();
		
		PriceAssessment price1 = new PriceAssessment();
		price1.setPrice(4);
		
		PriceAssessment price2 = new PriceAssessment();
		price2.setPrice(3);
 
		PriceAssessment price3 = new PriceAssessment();
		price3.setPrice(5);
 
		PriceAssessment price4 = new PriceAssessment();
		price4.setPrice(1);
		
		PriceAssessment price5 = new PriceAssessment();
		price4.setPrice(2);
 
		prices.addAll([price1, price2, price3, price4, price5]);
		
		BigDecimal idealPrice = (BigDecimal) strategy.getIdealPrice(prices);
		
		assert idealPrice == 3.6;
	 }
	
}
